package com.base.cn.platform.os.controller.manage.work;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.manage.function.SysFunction;
import com.base.cn.platform.os.entity.manage.work.SysUserWorkBench;
import com.base.cn.platform.os.service.manage.work.SysUserWorkBenchBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 工作台Controller
 *
 * @author s.li
 * @create 2018-04-13-9:33
 */
@RestController
@RequestMapping("/manage")
public class SysUserWorkBenchController extends BaseController {

    @Autowired
    private SysUserWorkBenchBiz sysUserWorkBenchBiz;

    /**
     * 查询工作台数据列表
     * @param userId 用户ID
     * @return List<SysUserWorkBench>
     */
    @RequestMapping("/findUserWordFunctionList")
    public List<SysUserWorkBench> findUserWordFunctionList(@RequestParam("userId") BigDecimal userId){
        return sysUserWorkBenchBiz.findUserWordFunctionList(userId);
    }

    /**
     * 排序工作的权限
     * @param userId 用户ID
     * @param paramsList 排序数据内容
     * @return Map<String,Object>
     */
    @RequestMapping("/updateWorkFunctionSort")
    public Map<String,Object> updateWorkFunctionSort(@RequestParam("userId") BigDecimal userId,
                                                     @RequestBody List<SysUserWorkBench> paramsList){
        sysUserWorkBenchBiz.updateWorkFunctionSort(userId,paramsList);
        return ResultUtil.SUCCESS("工作台权限排序成功");
    }

    /**
     * 获取未显示在工作上的权限列表
     * @param type 类型 provider运营支持，operate内容提供，prepare系统准备
     * @param userId 用户ID
     * @return 权限列表
     */
    @RequestMapping("/queryNotShowFunction")
    public List<SysFunction> queryNotShowFunction(@RequestParam("type") String type,@RequestParam("userId") BigDecimal userId){
        return sysUserWorkBenchBiz.queryNotShowFunction(type,userId);
    }

    /**
     * 添加工作台权限显示
     * @param userId 用户ID
     * @param functionIds 权限ID串
     * @param unSelectedIds 不显示的权限ID串
     * @return Map<String,Object>
     */
    @RequestMapping("/addUserWorkFunction")
    public Map<String,Object> addUserWorkFunction(@RequestParam("userId") BigDecimal userId,
                                           @RequestParam("functionIds") String functionIds,
                                           @RequestParam("unSelectedIds") String unSelectedIds){
        if(StringUtils.isNotEmpty(functionIds) && DataUtil.idIsNotNull(userId)){
            sysUserWorkBenchBiz.addUserWorkFunction(userId,functionIds,unSelectedIds);
        }
        return ResultUtil.SUCCESS("权限添加成功");
    }
}
